#!/bin/sh
# CC strlst
# possibly fragile script, but occasionally useful

[ -z "$EDITOR" ] && echo "no editor set!" && exit 1

ROOT="$HOME/.quests"

echo "enter a quest to edit using your default editor! ($EDITOR)
quests: "

ls -m $ROOT | sed 's/_/ /g'

echo -n "Name: "
read NAME
NAME=`echo $NAME | sed 's/ /_/g'`
MATCHED_NAME="$(ls -1 "$ROOT" | grep -i "$NAME" | head -1)"

[ -z "$MATCHED_NAME" ] && echo "no matching quest found!" && exit 1

"$EDITOR" "$ROOT"/$(ls -1 "$ROOT" | grep -i "$NAME" | head -1)/env
